package cn.taoshop.interceptor;

import cn.taoshop.category.vo.Category;
import cn.taoshop.index.action.InitBean;
import java.util.List;


import org.springframework.web.context.ContextLoader;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
public class InitInterceptor extends MethodFilterInterceptor{
	
	private InitBean initBean;
	
	public InitBean getInitBean() {
		return initBean;
	}

	public void setInitBean(InitBean initBean) {
		this.initBean = initBean;
	}

	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		
		List<Category> list = (List<Category>)ActionContext.getContext().getSession().get("cList");
		
		if(list != null) {
		//分类有效	

		return actionInvocation.invoke();
		} else{
			initBean = (InitBean)ContextLoader.getCurrentWebApplicationContext().getBean("initBean");
			initBean.init();
			return actionInvocation.invoke();
		}
	}
}
